package format;

import java.text.NumberFormat;
import java.util.Locale;

public class NumFormat {
    public static void main(String[] args) {
        numberFormat();
    }

    private static void numberFormat() {
        double d = 12345.676688000;
        NumberFormat nf = NumberFormat.getNumberInstance();
        System.out.println(nf.format(d));//12,345.677 默认只保留到小数点后三位
        nf.setMinimumIntegerDigits(9);
        System.out.println(nf.format(d));//12,345.677 整数部分大于2位按默认最大小数位数3位输出
        d = 1234.0;
        nf.setMaximumIntegerDigits(3);
        System.out.println(nf.format(d));//234
        nf = NumberFormat.getInstance();
        d = 12345.6766;
        nf.setMinimumFractionDigits(1);
        System.out.println(nf.format(d));//12,345.677 小数部分大于1位，按默认最大小数位数3位输出
        nf.setMinimumFractionDigits(5);
        System.out.println(nf.format(d));//12,345.67660 不够位数补0
        nf.setMaximumFractionDigits(1);
        System.out.println(nf.format(d));//12,345.7
        nf = NumberFormat.getNumberInstance(Locale.US);
        d = 12345.6789;
        System.out.println(nf.format(d));//12,345.679
        nf = NumberFormat.getNumberInstance(Locale.FRANCE);
        System.out.println(nf.format(d));//12 345,679
    }
}
